<?php
/**
 * (jobs)
 */
namespace App\Jobs\OverSeasIn;

use App\Models\OverSeasBa\InventoryBox;
use App\Models\OverSeasIn\Delivery;
use App\Models\OverSeasIn\DeliveryLogistics;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class InventoryBoxSyncTrackingNo implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $deliveryNos;

    /**
     * InventoryBoxSyncTrackingNo constructor.
     * @param $deliveryNos
     */
    public function __construct($deliveryNos)
    {
        $this->deliveryNos = $deliveryNos;
    }

    /**
     * Execute the job.
     * @return void
     */
    public function handle()
    {
        $this->exeFillData($this->deliveryNos);
    }

    private function exeFillData($deliveryNos){
        foreach ($deliveryNos as $deliveryNo){
            $delivery = Delivery::query()->where('delivery_no',$deliveryNo)->first();
            $tracking_no = DeliveryLogistics::query()->where('delivery_no',$deliveryNo)->value('tracking_no');
            InventoryBox::query()->where('batch_no',$delivery->batch_no)
                ->where('warehouse_id',$delivery->warehouse_id)
                ->update(['tracking_no' => $tracking_no]);
        }
    }
}
